﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;
using TarreOA.TarreOADAL;
public partial class page_AlterDetail : System.Web.UI.Page
{
    int id;
    protected void Page_Load(object sender, EventArgs e)
    {

      //  从session里取得user的属性
        id = Convert.ToInt32(Request["id"]);
       
        if (!IsPostBack)
        {



                if (Session["user"] == null)
                {
                    Session["ShowMessage"] = "用户未登录，请重新登录!";
                    Session["Backurl"] = "Login.aspx";
                    Response.Redirect("~/Message.aspx");
                }
                else
                {
                    TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
                    bool userFlag = false;
                    if (sucessUser.PopedomGroup.PopedomList != null)
                    {
                        foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                        {
                            if (var.PopedomId == 18)
                            {
                                userFlag = true;
                                break;
                            }
                       }
                      
                    }
                    if (!userFlag)
                    {
                        Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                        Session["Backurl"] = "Right.aspx";
                        Response.Redirect("~/Message.aspx");
                    }
                    else {
                        User user = new User();
                        Section section = new Section();
                        section.SectionId = 1;
                        user.UserId = sucessUser.UserId;
                        user.UserName = sucessUser.UserName;
                        user.Section = sucessUser.Section;
                        TarreOA.TarreOABLL.News news = new TarreOA.TarreOABLL.News();
                        TextNewsTitle.Text = news.readNews(id).Title;
                        FreeTextBox2.value = news.readNews(id).Detail;
                    }
                }
            

        }
    }
    protected void BtnSubmit_Click1(object sender, EventArgs e)
    {
        if (TextNewsTitle.Text.Trim().Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章标题不能为空')</script>");
            return;
        }
        string Title = TextNewsTitle.Text;

        if (FreeTextBox2.value.Trim().Equals(""))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('文章内容不能为空')</script>");
            return;
        }
        string Detail = FreeTextBox2.value;

        if (!TextNewsTitle.Equals(""))
        {
            if (!Detail.Equals(""))
            {
                ////////////////////////////////
                User user = (User)Session["user"];

                TarreOA.TarreOABLL.News news = new TarreOA.TarreOABLL.News();
                
                if (news.updateNews(id,Title, Detail))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入成功')</script>");
                    Response.Redirect("NewsManagementIframe.aspx");
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('插入失败')</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新闻内容不能为空')</script>");
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新闻标题不能为空')</script>");
        }
    }
    protected void BtnCancle_Click(object sender, EventArgs e)
    {
        Response.Redirect("NewsManagementIframe.aspx");
    }
}
